{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d2d11d44-fa60-4e87-a1de-f393320551d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'正向'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "import os\n",
    "import dashscope\n",
    "from dashscope.api_entities.dashscope_response import Role\n",
    "dashscope.api_key = \"sk-你的KEY\"\n",
    "\n",
    "# 封装模型响应函数\n",
    "def get_response(messages):\n",
    "    response = dashscope.Generation.call(\n",
    "        model='qwen-turbo',\n",
    "        messages=messages,\n",
    "        result_format='message'  # 将输出设置为message形式\n",
    "    )\n",
    "    return response\n",
    "    \n",
    "review = '这款音效特别好 给你意想不到的音质。'\n",
    "messages=[\n",
    "    {\"role\": \"system\", \"content\": \"你是一名舆情分析师，帮我判断产品口碑的正负向，回复请用一个词语：正向 或者 负向\"},\n",
    "    {\"role\": \"user\", \"content\": review}\n",
    "  ]\n",
    "\n",
    "response = get_response(messages)\n",
    "response.output.choices[0].message.content"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
